﻿@{
    ViewData["Title"] = "用户授权";
}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">部门</label>
                    <div class="layui-input-inline">
                        @Html.DeptSelect("DeptCode")
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="姓名" name="Name" id="Name">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-user-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-user-list" lay-filter="LAY-user-list"></table>
            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="grant"><i class="layui-icon layui-icon-edit"></i>授权</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reset"><i class="layui-icon layui-icon-edit"></i>密码重置</a>
            </script>
            </script>
        </div>
    </div>
</div>
<script type="text/javascript">
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.$
            , admin = layui.admin;
        //数据绑定
        table.render({
            elem: '#LAY-user-list'
            , url: '/Member/GetList' //模拟接口
            , method: 'post'
            , cols: [[
                { type: 'checkbox', fixed: 'left' }
                , { field: 'Name', title: '姓名', width: "10%" }
                , { field: 'Code', title: '代码', width: "15%" }
                , { field: 'DeptName', title: '部门', width: "15%" }
                , { field: 'MemberTypeStr', title: '类别', width: "8%" }
                , { field: 'Status', title: '状态', width: "15%" }
                , { field: 'right', title: '操作', width: 200, align: 'center', fixed: 'right', toolbar: '#table-content-list' }
            ]]
            , page: true
            , limit: 10
            , limits: [10, 15, 20, 25, 30]
            , text: { none: '暂无数据' }
        });

        //监听工具条
        table.on('tool(LAY-user-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'grant') {
                layer.open({
                    type: 2
                    , title: '授权'
                    , content: '/Role/AddUserRole?code=' + data.Code
                    , area: ["700px", "400px"]
                    , maxmin: true
                });
            }
            if (obj.event === 'reset') {
                layer.confirm("确定要重置密码", {
                    btn: ['确定', '取消']
                }, function() {
                        admin.req({
                            url: '/Member/ResetPwd' //实际使用请改成服务端真实接口
                            , method: 'post'
                            , data: "Id=" + data.Id
                            , done: function (res) {
                                layer.msg(res.msg);
                            }
                        });
                    }, function() {

                    }
                );
                
            }
        });
        //监听搜索
        form.on('submit(LAY-user-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-list', {
                where: field
            });
        });
    });
</script>
